﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Viettel.VOFFICE.Web.Models
{
    //[DebuggerDisplay("FirstName={FirstName}, LastName={LastName}")]
    public abstract class BaseModel
    {
        /// <summary>
        /// Gọi hàm validate model
        /// </summary>
        /// <returns>trả về list các lỗi</returns>
        public IEnumerable<ValidationResult> Validate()
        {
            var results = new List<ValidationResult>();
            var validationContext = new ValidationContext(this, null, null);
            if (!Validator.TryValidateObject(this, validationContext, results, validateAllProperties: true))
            {
            }
            return results;
        }

        /// <summary>
        /// Gọi hàm validate model
        /// </summary>
        /// <param name="outResults">List để chứa thông tin lỗi</param>
        /// <returns>true nếu model valid và false nếu invalid</returns>
        public bool IsValid(out List<ValidationResult> outResults) {
            var results = new List<ValidationResult>();
            var validationContext = new ValidationContext(this, null, null);
            var valid = Validator.TryValidateObject(this, validationContext, results, validateAllProperties: true);
            outResults = results;
            return valid;
        }
    }
}